<%@page import="tu.java.movie.Movie"%>
<%@page import="java.util.Calendar"%>
<%@page import="tu.java.utils.DateUtils"%>
<%@page import="java.util.Vector"%>
<%@page import="tu.java.projection.Projection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@include file="template/header.jspf" %>


<div class="content">
	
	<h2 id="title">Програма</h2>
	
	<%	String date = request.getParameter("date");
		if(date==null){
			date = DateUtils.sdfYMD_HMS().format(Calendar.getInstance().getTime());
		}
		Vector<Projection> projections = Projection.searchProjections(0, 0,date , "", 0);
	%>
		
	<form id="Programform" name="Programform" method="post" action="<%=request.getContextPath()%>/program.jsp">	
		<table class="formtable">
			<tr>
				<td align="right">Дата&nbsp;&nbsp;</td>
				<td align="left"><input readonly="readonly" type="text" name="date" id="date" class="tcal" value="<%=date%>" onchange="javascript:document.forms.Programform.submit();"/></td>				
			</tr>
			<tr></tr><tr></tr>
		</table>
			<table class="resulttable" border=0>
				<tr style="font-weight: bold;">
					<td>Име</td>
					<td>Описание</td>
					<td>Жанр</td>
					<td>Времетраене</td>
					<td>Вид</td>
					<td colspan="8">Прожекции</td>
				</tr>
			<%	int movieId=0;
			
				for(int i=0;i<projections.size();i++){ 
				Projection projection = projections.get(i);
				Movie movie = projection.getMovie();
				Movie next = projection.getMovie();
				if(movieId!=movie.getMovieId()){
					movieId = movie.getMovieId();
				%>			
				<tr>
					<td><%=movie.getMovieName()%></td>
					<td><%=movie.getMovieDescription().length()>50 ? movie.getMovieDescription().substring(0,49) + "..." : movie.getMovieDescription()%></td>
					<td><%=movie.printGenres()%></td>
					<td><%=movie.getMovieLenght()%></td>
					<td><%=movie.getMovieType()%></td>
				<%}%>
					<td><a href="reservation.jsp?pId=<%=projection.getProjectionId()%>"><%=projection.getProjectionBeginDateTime() %></a></td>
				<%
				if(i + 1 < projections.size() ){
					next = projections.get(i+1).getMovie();
				
				if(movieId!=next.getMovieId()){ %>				
				</tr>
				<%}}else{%>
				</tr>
				<%} %>
			<% movieId = movie.getMovieId();				
				} %>
		</table>
	</form>	
</div>
